package com.example.demo.model;


import java.util.HashMap;
import java.util.Objects;

class Key{
    private String name;
    private Integer id;

    public Key(String name) {
        this.name = name;
    }

    public Key(Integer id) {
        this.id = id;
    }

    public Key(String name, Integer id) {
        this.name = name;
        this.id = id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Key key = (Key) o;
        return Objects.equals(name, key.name) && Objects.equals(id, key.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, id);
    }
}

public class WithoutHashCode {
     public static void main(String[] args) {
         Key k1 = new Key(1);
         Key k2 = new Key(1);
         HashMap<Key,String> map = new HashMap<>();
         map.put(k1, "Key with id is 1");
         System.out.println(map.get(k2));
         System.out.println(Integer.toHexString(k1.hashCode()));
         System.out.println(Integer.toHexString(k2.hashCode()));
     }
 }

